home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_500 / wiconify / wutilities.lzh / _main.c next >
C/C++ Source or Header  |  1991-04-19  |  2KB  |  67 lines

  1. /*      _main.c         Copyright (C) 1985  Lattice, Inc.       */
  2.  
  3. /*                      Butchered by DPVC to remove unwanted    *
  4.  *                      I/O stuff - for small utility programs  *
  5.  *                      that do their simple I/O through the    *
  6.  *                      AmigaDOS Output() and Write() commands  */
  7.  
  8. #include <exec/types.h>
  9.  
  10. #define MAXARG 32              /* maximum command line arguments */
  11. #define QUOTE  '"'
  12.  
  13. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  14.  
  15. int argc;                       /* arg count */
  16. char *targv, *argv[MAXARG];     /* arg pointers */
  17.  
  18.  
  19. /*
  20.  *  _main()
  21.  *
  22.  *  c.o passes us the command line as a single character string.
  23.  *  While there is still room in the argument array,
  24.  *    Skip any blanks and quit if we're at the end of the line.
  25.  *    Get a pointer to the current arguement string location.
  26.  *    If we have a quoted string,
  27.  *      Skip the quote, and save the start of the string.
  28.  *      Look for the closeing quote or the end of the line.
  29.  *      If it's the end of the line, exit with error, otherwise erase the quote.
  30.  *    Otherwise,
  31.  *      Save the start of the string and find the first space in the string
  32.  *      If we're at the end of the line, quit,
  33.  *        Otherwise, end the parameter at the space and go on to the next one.
  34.  *  If there were no arguments passed, set argv to NULL, otherwise point it
  35.  *    to the first argv pointer.
  36.  *  Do the main C routine.
  37.  *  Exit with no error.
  38.  */
  39.  
  40. void _main(line)
  41. register char *line;
  42. {
  43.    register char **pargv;
  44.  
  45.    while (argc < MAXARG)
  46.    {
  47.       while (isspace(*line)) line++;
  48.       if (*line == '\0') break;
  49.       pargv = &argv[argc++];
  50.       if (*line == QUOTE)
  51.       {
  52.          *pargv = ++line;
  53.          while ((*line != '\0') && (*line != QUOTE)) line++;
  54.          if (*line == '\0') _exit(1); else *line++ = '\0';
  55.       } else {
  56.          *pargv = line;
  57.          while ((*line != '\0') && (!isspace(*line))) line++;
  58.          if (*line == '\0')  break; else *line++ = '\0';
  59.       }
  60.    }
  61.    targv = (argc == 0) ? NULL : (char *)&argv[0];
  62.  
  63.    main(argc,targv);
  64.  
  65.    _exit(0);
  66. }
  67.